home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / perl / makedepend < prev    next >
Encoding:
Text File  |  1991-11-14  |  3.9 KB  |  135 lines

  1. #!/bin/sh
  2. # : makedepend.SH,v 1302cRevision: 4.0.1.3 1302cDate: 91/11/05 17:56:33 $
  3. #
  4. # $Log:    makedepend.SH,v $
  5. # Revision 4.0.1.3  91/11/05  17:56:33  lwall
  6. # patch11: various portability fixes
  7. # Revision 4.0.1.2  91/06/07  15:40:06  lwall
  8. # patch4: fixed cppstdin to run in the right directory
  9. # Revision 4.0.1.1  91/06/07  11:20:06  lwall
  10. # patch4: Makefile is no longer self-modifying code under makedepend
  11. # Revision 4.0  91/03/20  01:27:04  lwall
  12. # 4.0 baseline.
  13.  
  14. export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)
  15.  
  16. cat='/sprite/cmds.sun3/cat'
  17. cppflags=' -I/usr/include -I/usr/include/sun'
  18. cp='/sprite/cmds.sun3/cp'
  19. cppstdin='/sprite/cmds.sun3/cpp'
  20. cppminus=''
  21. echo='echo'
  22. egrep='/sprite/cmds.sun3/egrep'
  23. expr='/sprite/cmds.sun3/expr'
  24. mv='/sprite/cmds.sun3/mv'
  25. rm='/sprite/cmds.sun3/rm'
  26. sed='/sprite/cmds.sun3/sed'
  27. sort='/sprite/cmds.sun3/sort'
  28. test='test'
  29. tr='/sprite/cmds.sun3/tr'
  30. uniq='/sprite/cmds.sun3/uniq'
  31.  
  32. $cat /dev/null >.deptmp
  33. $rm -f *.c.c c/*.c.c
  34. if test -f Makefile; then
  35.     cp Makefile makefile
  36. fi
  37. mf=makefile
  38. if test -f $mf; then
  39.     defrule=`<$mf sed -n        \
  40.     -e '/^\.c\.o:.*;/{'        \
  41.     -e    's/\$\*\.c//'        \
  42.     -e    's/^[^;]*;[     ]*//p'    \
  43.     -e    q                \
  44.     -e '}'                \
  45.     -e '/^\.c\.o: *$/{'        \
  46.     -e    N                \
  47.     -e    's/\$\*\.c//'        \
  48.     -e    's/^.*\n[     ]*//p'        \
  49.     -e    q                \
  50.     -e '}'`
  51. fi
  52. case "$defrule" in
  53. '') defrule='$(CC) -c $(CFLAGS)' ;;
  54. esac
  55.  
  56. make clist || ($echo "Searching for .c files..."; \
  57.     $echo *.c | $tr ' ' '\012' | $egrep -v '\*' >.clist)
  58. for file in `$cat .clist`; do
  59. # for file in `cat /dev/null`; do
  60.     case "$file" in
  61.     *.c) filebase=`basename $file .c` ;;
  62.     *.y) filebase=`basename $file .c` ;;
  63.     esac
  64.     $echo "Finding dependencies for $filebase.o."
  65.     $sed -n <$file >$file.c \
  66.     -e "/^${filebase}_init(/q" \
  67.     -e '/^#/{' \
  68.     -e 's|/\*.*$||' \
  69.     -e 's|\\$||' \
  70.     -e p \
  71.     -e '}'
  72.     $cppstdin -I/usr/local/include -I. $cppflags $cppminus <$file.c | sed -e 's#\.[0-9][0-9]*\.c#'"$file.c#" | \
  73.     $sed \
  74.     -e 's/^[     ]*#[     ]*line/#/' \
  75.     -e '/^# *[0-9][0-9]* *"/!d' \
  76.     -e 's/^.*"\(.*\)".*$/'$filebase'.o: \1/' \
  77.     -e 's|: \./|: |' \
  78.     -e 's|\.c\.c|.c|' | \
  79.     $uniq | $sort | $uniq >> .deptmp
  80. done
  81.  
  82. $sed <$mf >$mf.new -e '1,/^# AUTOMATICALLY/!d'
  83.  
  84. make shlist || ($echo "Searching for .SH files..."; \
  85.     $echo *.SH | $tr ' ' '\012' | $egrep -v '\*' >.shlist)
  86. if $test -s .deptmp; then
  87.     for file in `cat .shlist`; do
  88.     $echo `$expr X$file : 'X\(.*\).SH'`: $file config.sh \; \
  89.         /bin/sh $file >> .deptmp
  90.     done
  91.     $echo "Updating $mf..."
  92.     $echo "# If this runs make out of memory, delete /usr/include lines." \
  93.     >> $mf.new
  94.     $sed 's|^\(.*\.o:\) *\(.*/.*\.c\) *$|\1 \2; '"$defrule \2|" .deptmp \
  95.        >>$mf.new
  96. else
  97.     make hlist || ($echo "Searching for .h files..."; \
  98.     $echo *.h | $tr ' ' '\012' | $egrep -v '\*' >.hlist)
  99.     $echo "You don't seem to have a proper C preprocessor.  Using grep instead."
  100.     $egrep '^#include ' `cat .clist` `cat .hlist`  >.deptmp
  101.     $echo "Updating $mf..."
  102.     <.clist $sed -n                            \
  103.     -e '/\//{'                            \
  104.     -e   's|^\(.*\)/\(.*\)\.c|\2.o: \1/\2.c; '"$defrule \1/\2.c|p"    \
  105.     -e   d                                \
  106.     -e '}'                                \
  107.     -e 's|^\(.*\)\.c|\1.o: \1.c|p' >> $mf.new
  108.     <.hlist $sed -n 's|\(.*/\)\(.*\)|s= \2= \1\2=|p' >.hsed
  109.     <.deptmp $sed -n 's|c:#include "\(.*\)".*$|o: \1|p' | \
  110.        $sed 's|^[^;]*/||' | \
  111.        $sed -f .hsed >> $mf.new
  112.     <.deptmp $sed -n 's|c:#include <\(.*\)>.*$|o: /usr/include/\1|p' \
  113.        >> $mf.new
  114.     <.deptmp $sed -n 's|h:#include "\(.*\)".*$|h: \1|p' | \
  115.        $sed -f .hsed >> $mf.new
  116.     <.deptmp $sed -n 's|h:#include <\(.*\)>.*$|h: /usr/include/\1|p' \
  117.        >> $mf.new
  118.     for file in `$cat .shlist`; do
  119.     $echo `$expr X$file : 'X\(.*\).SH'`: $file config.sh \; \
  120.         /bin/sh $file >> $mf.new
  121.     done
  122. fi
  123. $rm -f $mf.old
  124. $cp $mf $mf.old
  125. $cp $mf.new $mf
  126. $rm $mf.new
  127. $echo "# WARNING: Put nothing here or make depend will gobble it up!" >> $mf
  128. $rm -f .deptmp `sed 's/\.c/.c.c/' .clist` .shlist .clist .hlist .hsed
  129.  
  130.